/**
 * ComboBox Component Item Class - Created by FlashFrameLess Team OCT/2008
 *
 * @author		FabioTNT / FlashFrameLessTeam - http://www.flashframeless.com/
 * @version		1.0
 */

package com.flashframeless.components.ui.combo {

	import flash.display.MovieClip;
	import flash.display.Sprite;
	//
	import flash.events.MouseEvent;
	import flash.events.KeyboardEvent;
	//
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	//
	import flash.ui.Keyboard;
	//
	import caurina.transitions.Tweener;
	import caurina.transitions.properties.ColorShortcuts;
	
	public class Item extends Sprite {
		
		private		var _hitArea	: MovieClip;
		private		var _label		: TextField;
		private		var _backGround	: MovieClip;
		private		var _overColor	: Number = 0x534C32;
		private		var _initColor	: Number = 0xAEA98B;
		private		var _initWidth	: uint;
		private 	var _textAlign	: String = 'left';
		protected 	var _data		: Object;
		
		public function Item():void {
			
			ColorShortcuts.init();
			
			setupInteractions();
			
		}
		
		private function setupInteractions():void {
			
			_label 			= labelTxt;
			_hitArea 		= hitMc;			
			
			_backGround		= bgMc;
			
			_hitArea.alpha 	= 0;
			
			_initWidth 		= this.width;
			
			_hitArea.addEventListener( MouseEvent.MOUSE_OVER, 	onOver  );
			_hitArea.addEventListener( MouseEvent.MOUSE_OUT, 	onOut 	);
			_hitArea.addEventListener( MouseEvent.MOUSE_UP, 	onClick	);
			
			_hitArea.buttonMode = true;
			
		}
		
		internal function setWidth( maxWidth:uint ):void {
			
			_hitArea.width 	= _backGround.width = maxWidth;
			_hitArea.x 		= _backGround.x 	= -_backGround.width + _initWidth;
			
			switch( _textAlign ) {
				
				case 'left':
					
					_label.x 		= _backGround.x;
					
				break
				
				case 'center':
				
					_label.x 		= _backGround.x + _backGround.width / 2 - _label.width/2;
					
				break
				
				case 'right':
					
					_label.x 		= _backGround.x + _backGround.width - _label.width;
					
				break
				
			}
			
		}
		
		/*-------------------------------------------------------------------------------------------------*\
		|* Handlers ---------------------------------------------------------------------------------------*|
		\*-------------------------------------------------------------------------------------------------*/
		
		/**
		 * OnOver Handler.
		 *
		 * @param	evt		MouseEvent
		 * @return			void
		 */
		private function onOver( evt:MouseEvent = null ):void {
			
			//Over
			Tweener.addTween( _backGround, { _color:_overColor } );
			
		}
		
		/**
		 * OnOut Handler.
		 *
		 * @param	evt		MouseEvent
		 * @return			void
		 */
		private function onOut( evt:MouseEvent = null ):void {
			
			//Out
			Tweener.addTween( _backGround, { _color:_initColor } );
			
		}
		
		/**
		 * onClick Handler.
		 *
		 * @param	evt		MouseEvent
		 * @return			void
		 */
		private function onClick( evt:MouseEvent = null ):void {
			
			parent['parent'].setValue( evt );
			
		}
		
		/*-------------------------------------------------------------------------------------------------*\
		|* Getters e Setters ------------------------------------------------------------------------------*|
		\*-------------------------------------------------------------------------------------------------*/
		
		/**
		 * Parameters Setter.
		 *
		 * @param	params	Object
		 * @return			void
		 */
		public function set parameters( params:Object ):void {
			
			_label.autoSize	= TextFieldAutoSize.LEFT;
			_label.text 	= params.label;
			_data			= params;
			
		}
		
		/**
		 * Text Align Setter.
		 *
		 * @param	align	String
		 * @return			void
		 */
		public function set textAlign( align:String ):void {
			
			_textAlign = align;
			
		}
		
		/**
		 * Data Getter.
		 *
		 * @return			String
		 */
		public function get data():Object {
			
			return _data;
			
		}
		
	}
}